﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Speech.Synthesis;
using System.Text;
using System.Threading.Tasks;
using Windows.System;
using 高级控件演示.Domain;
using 高级控件演示.Views;

namespace 高级控件演示.ViewModels
{
    public class ItemsControlDemoViewModel : BindableBase
    {
        private readonly IDialogService _dialogService;

        public DelegateCommand<PigeonInfo> SpeekCommand { get; private set; }
        public DelegateCommand<PigeonInfo> PlayCommand { get; private set; }

        private SpeechSynthesizer synthesizer = new SpeechSynthesizer();

        private ObservableCollection<PigeonInfo> pigeonList;

        public ObservableCollection<PigeonInfo> PigeonList
        {
            get
            {
                return pigeonList;
            }
            set
            {
                pigeonList = value;RaisePropertyChanged();
            }
        }

        public ItemsControlDemoViewModel(IDialogService dialogService)
        {
            _dialogService = dialogService;
            SpeekCommand = new DelegateCommand<PigeonInfo>(SpeekCommandFunc);
            PlayCommand = new DelegateCommand<PigeonInfo>(PlayCommandFunc);

            LoadData();
        }

        private void PlayCommandFunc(PigeonInfo pigeonInfo)
        {
            OpenDialogForSetPer(pigeonInfo);
        }

        #region 对话框打开操作
        private void OpenDialogForSetPer(PigeonInfo pigeonInfo)
        {
            DialogParameters dlgParams = new DialogParameters();
            dlgParams.Add("PigeonInfo", pigeonInfo);
            _dialogService.ShowDialog("PlayPigeonDialog", dlgParams, result =>
            {
            });
        }
        #endregion

        private void SpeekCommandFunc(PigeonInfo obj)
        {
            synthesizer.SpeakAsync(obj.Desc);
        }

        private void LoadData()
        {
            string tankDesc = "坦克,颜色:雨点,雄鸽,体重:2.2斤\r\n" +
                              "芷儿凤凰鸽舍镇棚鸽\r\n"+
                              "配铁扇公主出过黑色的小崽";
            string tankName = "坦克";
            string hjgDesc = "黑金刚,颜色:纯黑,雄鸽,体重:1.9斤\r\n"+
                             "方头,年轻力壮,配雨点皇后,出方头概率大\r\n"+
                             "小崽颜色,大概率出黑";
            string hjgName = "黑金刚";
            string ydhhDesc = "雨点皇后,颜色:深雨点,雌鸽,体重:1.8斤\r\n" +
                              "方头,年轻的黄金种母,配黑金刚\r\n"+
                              "小崽颜色,大概率出黑,方头概率极大";
            string ydhhName = "雨点皇后";
            string xftDesc = "小方头,颜色:深雨点,雌鸽,体重:1.7斤\r\n"+
                                "方头,青年雌鸽,配黑金刚,配坦克都可\r\n" +
                                    "小崽颜色,大概率出黑,方头概率极大";
            string xftName = "小方头";
            string xytDesc = "小圆头,颜色:深雨点,雄鸽,体重:1.8斤\r\n" +
                             "方头,青年雄鸽,配铁扇公主,\r\n" +
                             "小崽颜色,可能出黑和雨点,方头概率很小";
            string xytName = "小圆头";
            string xhmDesc = "小黑母,颜色:纯黑,雌鸽,体重:1.8斤\r\n"+
                             "圆头,年轻的种母,配黑金刚,配坦克都可\r\n" +
                             "小崽颜色,基本出黑,方头概率50%";
            string xhmName = "小黑母";
            string tsgzDesc = "铁扇公主,颜色:雪花,雌鸽,体重:1.8斤\r\n" +
                              "圆头,年轻的黄金种母,配黑金刚,配坦克都可以\r\n" +
                              "小崽颜色,大概率出黑和雪花,方头概率比较大";
            string tsgzName = "铁扇公主";

            PigeonList = new ObservableCollection<PigeonInfo>()
            {
                new PigeonInfo() { PigeonImage = "Resources/Pigeons/坦克2.png",Desc =tankDesc,PigeonName = tankName},
                new PigeonInfo() {PigeonImage = "Resources/Pigeons/坦克3.png",Desc = tankDesc,PigeonName = tankName },
                new PigeonInfo() { PigeonImage = "Resources/Pigeons/雨点皇后1.png", Desc = ydhhDesc,PigeonName = ydhhName },
                new PigeonInfo() {PigeonImage = "Resources/Pigeons/雨点皇后2.png", Desc = ydhhDesc,PigeonName = ydhhName},
                new PigeonInfo(){PigeonImage = "Resources/Pigeons/雨点皇后3.png", Desc = ydhhDesc,PigeonName = ydhhName},
                new PigeonInfo(){PigeonImage = "Resources/Pigeons/雨点皇后4.png", Desc = ydhhDesc,PigeonName = ydhhName},
                new PigeonInfo(){PigeonImage = "Resources/Pigeons/雨点皇后5.png", Desc = ydhhDesc,PigeonName = ydhhName},
                new PigeonInfo(){PigeonImage = "Resources/Pigeons/黑金刚2.png",Desc=hjgDesc,PigeonName = hjgName},
                new PigeonInfo(){PigeonImage = "Resources/Pigeons/小方头1.png",Desc=xftDesc,PigeonName = xftName},
                new PigeonInfo(){PigeonImage = "Resources/Pigeons/小方头2.png",Desc=xftDesc,PigeonName = xftName},
                new PigeonInfo(){PigeonImage = "Resources/Pigeons/小圆头1.png",Desc=xytDesc,PigeonName = xftName},
                new PigeonInfo(){PigeonImage = "Resources/Pigeons/小圆头2.png",Desc=xytDesc,PigeonName = xftName},
                new PigeonInfo(){PigeonImage = "Resources/Pigeons/铁扇公主.png",Desc=tsgzDesc,PigeonName = tsgzName},
                new PigeonInfo(){PigeonImage = "Resources/Pigeons/铁扇公主2.png",Desc=tsgzDesc,PigeonName = tsgzName},
                new PigeonInfo(){PigeonImage = "Resources/Pigeons/铁扇公主3.png",Desc=tsgzDesc,PigeonName = tsgzName},
                new PigeonInfo(){PigeonImage = "Resources/Pigeons/铁扇公主4.png",Desc=tsgzDesc,PigeonName = tsgzName},
                new PigeonInfo(){PigeonImage = "Resources/Pigeons/小黑母1.png",Desc=xhmDesc,PigeonName = xhmName},
                new PigeonInfo(){PigeonImage = "Resources/Pigeons/小黑母2.png",Desc=xhmDesc,PigeonName = xhmName},
            };

            for (int i = 0; i < PigeonList.Count; i++)
            {
                PigeonList[i].PigeonImage = "/" + PigeonList[i].PigeonImage;
                PigeonList[i].Num = (i + 1).ToString();
            }
        }
    }
}
